//
//  ShopDetailController.m
//  ShopDemo
//
//  Created by 飞扬的青春 on 2018/7/15.
//  Copyright © 2018年 飞扬的青春. All rights reserved.
//

#import "ShopDetailController.h"
#import "ShoppingView.h"
#import "AddressCon.h"
#import "MorePingLunController.h"
#import "LoginController.h"

@interface ShopDetailController ()<UITableViewDelegate,UITableViewDataSource,SDCycleScrollViewDelegate>

@property(nonatomic,strong)UITableView *listTableview;
@property(nonatomic,strong)UIView *headerview;
@property(nonatomic,strong)UIView *backview;
@property(nonatomic,strong)NSDictionary *maindic;
@property(nonatomic,assign)NSInteger footHeight;

@property(nonatomic,strong)NSArray *imgeArray;
@property(nonatomic,strong)NSArray *ggArray;

@property(nonatomic,strong)NSMutableArray *butArray;
@property(nonatomic,strong)NSString *guigeStr;
@property(nonatomic,strong)NSString *guigeId;
@property(nonatomic,strong)NSString *shangpingId;
@property(nonatomic,strong)NSString *guigePrice;
@property(nonatomic,strong)MineButton *shoucanBtn;


@end

@implementation ShopDetailController
-(NSMutableArray *)butArray{
    if (!_butArray) {
        _butArray = [NSMutableArray arrayWithCapacity:10];
    }
    return _butArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self showShopDetailImageDataMethodWithUrl:[MethodClass returnUrlSetStrWSDLURL:self.urlStr]];
    NSString *ggStr = [NSString stringWithFormat:@"/dashop/attribute/app/list.do?GOODS_ID=%@",_usdic[@"GOODS_ID"]];
    [self GGXHshowShopDetailImageDataMethodWithUrl:[MethodClass returnUrlSetStrWSDLURL:ggStr]];
    [self createTableviewMethod];
    [self creatFootViewMethod];
    [self creatBackviewMethod];
    
}

-(void)creatBackviewMethod{
    self.backview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
    self.backview.backgroundColor = [[UIColor grayColor] colorWithAlphaComponent:0.5];
    self.backview.hidden = YES;
    [self.navigationController.view addSubview:self.backview];
}

-(void)creatFootViewMethod{
    
    UIView *footview = [UIView new];
    footview.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:footview];
    if (kScreenHeight == 812) {
        footview.sd_layout
        .bottomSpaceToView(self.view, 34)
        .leftSpaceToView(self.view, 0)
        .rightSpaceToView(self.view, 0)
        .heightIs(51*kJLXWidthScale);
    }else{
        footview.sd_layout
        .bottomSpaceToView(self.view, 0)
        .leftSpaceToView(self.view, 0)
        .rightSpaceToView(self.view, 0)
        .heightIs(51*kJLXWidthScale);
    }
    MineButton *onebtn = [MineButton buttonWithType:UIButtonTypeCustom];
    self.shoucanBtn = onebtn;
    [onebtn addTarget:self action:@selector(shoucangButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [footview addSubview:onebtn];
    onebtn.sd_layout
    .leftSpaceToView(footview, 0)
    .topSpaceToView(footview, 1)
    .heightIs(50*kJLXWidthScale)
    .widthIs(kScreenWidth/3/2);
    
    UIImageView *imagevi = [UIImageView new];
    onebtn.mineimagevi = imagevi;
    imagevi.image = [UIImage imageNamed:@"icon_collection.png"];
    [onebtn addSubview:imagevi];
    imagevi.sd_layout
    .topSpaceToView(onebtn, 5*kJLXWidthScale)
    .leftSpaceToView(onebtn, 17*kJLXWidthScale)
    .rightSpaceToView(onebtn, 17*kJLXWidthScale)
    .heightIs(25*kJLXWidthScale);
    
    UILabel *titlab = [UILabel new];
    titlab.textAlignment = NSTextAlignmentCenter;
    titlab.text = @"收藏";
    titlab.font = [UIFont systemFontOfSize:13*kJLXWidthScale];
    [onebtn addSubview:titlab];
    titlab.sd_layout
    .topSpaceToView(imagevi, 0)
    .leftSpaceToView(onebtn, 0)
    .rightSpaceToView(onebtn, 0)
    .heightIs(20*kJLXWidthScale);
    
    MineButton *twobtn = [MineButton buttonWithType:UIButtonTypeCustom];
    [twobtn addTarget:self action:@selector(shoppingButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    [footview addSubview:twobtn];
    twobtn.sd_layout
    .leftSpaceToView(onebtn, 0)
    .topSpaceToView(footview, 1)
    .heightIs(50*kJLXWidthScale)
    .widthIs(kScreenWidth/3/2);
    
    UIImageView *imagevi01 = [UIImageView new];
    imagevi01.image = [UIImage imageNamed:@"tab_04_0.png"];
    [twobtn addSubview:imagevi01];
    imagevi01.sd_layout
    .topSpaceToView(twobtn, 5*kJLXWidthScale)
    .leftSpaceToView(twobtn, 12*kJLXWidthScale)
    .rightSpaceToView(twobtn, 12*kJLXWidthScale)
    .heightIs(32*kJLXWidthScale);
    
    UILabel *titlab01 = [UILabel new];
    titlab01.textAlignment = NSTextAlignmentCenter;
    titlab01.text = @"购物车";
    titlab01.font = [UIFont systemFontOfSize:13*kJLXWidthScale];
    [twobtn addSubview:titlab01];
    titlab01.sd_layout
    .topSpaceToView(imagevi01, -5*kJLXWidthScale)
    .leftSpaceToView(twobtn, 0)
    .rightSpaceToView(twobtn, 0)
    .heightIs(20*kJLXWidthScale);
    
    
    
    
    
    MineButton *thirdbtn = [MineButton buttonWithType:UIButtonTypeCustom];
    [thirdbtn addTarget:self action:@selector(addShoppingButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    thirdbtn.backgroundColor = [UIColor orangeColor];
    [thirdbtn setTitle:@"加入购物车" forState:UIControlStateNormal];
    [thirdbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [footview addSubview:thirdbtn];
    thirdbtn.sd_layout
    .leftSpaceToView(twobtn, 0)
    .topSpaceToView(footview, 1)
    .heightIs(50*kJLXWidthScale)
    .widthIs(kScreenWidth/3);
    
    
    
    MineButton *fourbtn = [MineButton buttonWithType:UIButtonTypeCustom];
    [fourbtn addTarget:self action:@selector(lijiShoppingButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    fourbtn.backgroundColor = [UIColor redColor];
    [fourbtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [fourbtn setTitle:@"立即购买" forState:UIControlStateNormal];
    [footview addSubview:fourbtn];
    fourbtn.sd_layout
    .leftSpaceToView(thirdbtn, 0)
    .topSpaceToView(footview, 1)
    .heightIs(50*kJLXWidthScale)
    .widthIs(kScreenWidth/3);
    
    
    
}
//收藏
-(void)shoucangButtonAction:(MineButton *)sender{
    NSString *username = [UserDefault objectForKey:LogUserName];
    if (username && username.length > 0) {
        sender.selected = !sender.selected;
        if (sender.selected == YES) {
            sender.mineimagevi.image = [UIImage imageNamed:@"icon_collection_ed.png"];
            NSString *urlstr = [NSString stringWithFormat:@"/dashop/collection/app/save.do?GOODS_ID=%@&USER_ID=%@",self.usdic[@"GOODS_ID"],[UserDefault objectForKey:LogUserID]];
            NSString *endstr = [MethodClass returnUrlSetStrWSDLURL:urlstr];
            [self AddShouCangJiaMethodWithUrl:endstr];
        }else{
            if (self.maindic[@"ISNOCOLLECTION"]) {
                NSString *urlstr = [NSString stringWithFormat:@"/dashop/collection/app/delete.do?COLLECTION_ID=%@&USER_ID=%@&GOODS_ID=%@",self.maindic[@"COLLECTION_ID"],[UserDefault objectForKey:LogUserID],self.usdic[@"GOODS_ID"]];
                NSString *endstr = [MethodClass returnUrlSetStrWSDLURL:urlstr];
                [self deletShouCangJiaMethodWithUrl:endstr];
                sender.mineimagevi.image = [UIImage imageNamed:@"icon_collection.png"];
            }
        }
    }else{
        LoginController *loginVC = [[LoginController alloc]init];
        loginVC.logBlock = ^(NSDictionary *logdic) {
            
        };
        loginVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:loginVC animated:YES];
    }
    
    
}

//限时抢购按钮图
-(void)AddShouCangJiaMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
        
    } successBlock:^(id response) {
        NSDictionary *dic = response;
        if ([dic[@"RESULT"] integerValue] == 1) {
            [[NSOperationQueue mainQueue]addOperationWithBlock:^{
                [self alerWithMessage:dic[@"MESSAGE"]];
            }];
        }
        
    } failBlock:^(NSError *error) {
        
        
    }];
    
}

//限时抢购按钮图
-(void)deletShouCangJiaMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
        
    } successBlock:^(id response) {
        NSDictionary *dic = response;
        if ([dic[@"RESULT"] integerValue] == 1) {
            [self alerWithMessage:dic[@"MESSAGE"]];
        }
    } failBlock:^(NSError *error) {
        
        
    }];
    
}


//购物车
-(void)shoppingButtonAction:(MineButton *)sender{
    NSString *username = [UserDefault objectForKey:LogUserName];
    if (username && username.length > 0) {
        self.tabBarController.selectedIndex = 2;
    }else{
        LoginController *loginVC = [[LoginController alloc]init];
        loginVC.logBlock = ^(NSDictionary *logdic) {
            
        };
        loginVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:loginVC animated:YES];
    }
}
//加入购物车
-(void)addShoppingButtonAction:(MineButton *)sender{
    NSString *username = [UserDefault objectForKey:LogUserName];
    if (username && username.length > 0) {
        self.backview.hidden = NO;
        [self.backview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        NSInteger height = 230*kJLXWidthScale + self.ggArray.count *35*kJLXWidthScale + 60*kJLXWidthScale;
        NSInteger shopheight;
        if (height < kScreenHeight/2) {
            shopheight = kScreenHeight/2;
        }else{
            shopheight = height;
        }
        ShoppingView *shopview = [[ShoppingView alloc]initWithFrame:CGRectMake(0, kScreenHeight-shopheight, kScreenWidth, shopheight)];
        shopview.backgroundColor = [UIColor whiteColor];
        NSString *imageurl = self.maindic[@"GOODS_PIC"];
        NSArray *imagearr = [imageurl componentsSeparatedByString:@","];
        NSString *strurl = [MethodClass returnUrlSetStrWSDLURL:imagearr[0]];
        NSURL *uURL = [NSURL URLWithString:strurl];
        [shopview.titimagevi sd_setImageWithURL:uURL];
        shopview.titlab.text = [NSString stringWithFormat:@"%@",self.maindic[@"GOODS_NAME"]];
        //商品添加到购物车
        /*
         GOODS_ID商品ID
         GOODS_NAME商品名称
         GOODS_ATTRIBUTE_ID 商品规格ID
         GOODS_ATTRIBUTE商品规格
         GOODS_NUM数量
         GOODS_PRICE单价
         USERNAME账号
         */
        
        __weak typeof(self)weakself = self;
        shopview.shopingBlock = ^(NSInteger shopnum) {
            NSString *shopnumstr = [NSString stringWithFormat:@"%ld",shopnum];
            NSString *strurl = [NSString stringWithFormat:@"/dashop/shoppingcar/app/add.do?GOODS_ID=%@&GOODS_NAME=%@&GOODS_ATTRIBUTE_ID=%@&GOODS_ATTRIBUTE=%@&GOODS_NUM=%@&GOODS_PRICE=%@&USERNAME=%@",self.shangpingId,self.maindic[@"GOODS_NAME"],self.guigeId,self.guigeStr,shopnumstr,self.guigePrice,[UserDefault objectForKey:LogUserID]];
            NSString *endstr = [MethodClass returnUrlSetStrWSDLURL:strurl];
            NSString  *newUrlString = [endstr stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
            [weakself addShopingCarRequestMethodWithUrl:newUrlString];
            weakself.backview.hidden = YES;
            [weakself.backview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        };
//        NSInteger numwidth = 0;
//        for (int i = 0; i < self.ggArray.count; i ++) {
//            NSDictionary *ggdic = self.ggArray[i];
//            NSString *constr = ggdic[@"ATTRIBUTE"];
//            CGSize size = [constr sizeWithFont:[UIFont systemFontOfSize:15*kJLXWidthScale] constrainedToSize: CGSizeMake(MAXFLOAT,35*kJLXWidthScale) lineBreakMode:NSLineBreakByWordWrapping];
//            numwidth = 20*kJLXWidthScale + size.width + numwidth;
//
//        }
//        UIScrollView *ggscview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 35*kJLXWidthScale)];
//        ggscview.contentSize = CGSizeMake(numwidth,35*kJLXWidthScale);
//        [shopview.ggbaview addSubview:ggscview];
        
       
        for (int i = 0; i < self.ggArray.count; i ++) {
            NSDictionary *ggdic = self.ggArray[i];
            NSString *constr = ggdic[@"ATTRIBUTE"];
            CGSize buttonsize = [constr sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18*kJLXWidthScale]}];
            MineButton *btn = [MineButton buttonWithType:UIButtonTypeCustom];
            [shopview.ggbaview addSubview:btn];
            btn.sd_layout
            .topSpaceToView(shopview.ggbaview, 8*kJLXWidthScale + (30*kJLXWidthScale + 5*kJLXWidthScale)*i)
            .leftSpaceToView(shopview.ggbaview, 8*kJLXWidthScale)
            .widthIs(buttonsize.width)
            .heightIs(30*kJLXWidthScale);
            //调节button大小
            btn.titleLabel.font = [UIFont systemFontOfSize:13*kJLXWidthScale];
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            btn.layer.masksToBounds = YES;
            btn.layer.cornerRadius = 8*kJLXWidthScale;
            btn.usinfo = ggdic;
            btn.tag = 370 + i;
            btn.backgroundColor = [UIColor lightGrayColor];
//            num = btn.frame.origin.x + buttonsize.width ;
            [btn setTitle:constr forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(ggButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            [self.butArray addObject:btn];
            if (i == 0) {
                btn.backgroundColor = [UIColor redColor];
                shopview.savelab.text = [NSString stringWithFormat:@"库存%@",ggdic[@"ATTRIBUTENUM"]];
                shopview.savelab.tag = 1001;
                shopview.pricelab.text = [NSString stringWithFormat:@"￥%.2f",[ggdic[@"ATTRIBUTEPRICE"] floatValue]];
                shopview.pricelab.tag = 1002;
                self.guigeId = ggdic[@"ATTRIBUTE_ID"];
                self.guigeStr = ggdic[@"ATTRIBUTE"];
                self.shangpingId = self.maindic[@"GOODS_ID"];
                self.guigePrice = ggdic[@"ATTRIBUTEPRICE"];
            }
        }
        [self.backview addSubview:shopview];
    }else{
        LoginController *loginVC = [[LoginController alloc]init];
        loginVC.logBlock = ^(NSDictionary *logdic) {
            
        };
        loginVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:loginVC animated:YES];
    }
    
    
}
//立即购买
-(void)lijiShoppingButtonAction:(MineButton *)sender{
    NSString *username = [UserDefault objectForKey:LogUserName];
    if (username && username.length > 0) {
        self.backview.hidden = NO;
        [self.backview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
        NSInteger height = 230*kJLXWidthScale + self.ggArray.count *35*kJLXWidthScale + 60*kJLXWidthScale;
        NSInteger shopheight;
        if (height < kScreenHeight/2) {
            shopheight = kScreenHeight/2;
        }else{
            shopheight = height;
        }
        ShoppingView *shopview = [[ShoppingView alloc]initWithFrame:CGRectMake(0, kScreenHeight-shopheight, kScreenWidth, shopheight)];
        shopview.backgroundColor = [UIColor whiteColor];
        NSString *imageurl = self.maindic[@"GOODS_PIC"];
        NSArray *imagearr = [imageurl componentsSeparatedByString:@","];
        NSString *strurl = [MethodClass returnUrlSetStrWSDLURL:imagearr[0]];
        NSURL *uURL = [NSURL URLWithString:strurl];
        [shopview.titimagevi sd_setImageWithURL:uURL];
        shopview.titlab.text = [NSString stringWithFormat:@"%@",self.maindic[@"GOODS_NAME"]];
        //商品添加到购物车
        __weak typeof(self)weakself = self;
        shopview.shopingBlock = ^(NSInteger shopnum) {
            NSString *shopnumstr = [NSString stringWithFormat:@"%ld",shopnum];
            AddressCon *addVC = [[AddressCon alloc]init];
            addVC.sumPriceStr = [NSString stringWithFormat:@"%.2f",shopnum * [self.guigePrice floatValue]];
            NSDictionary *orderdic = @{@"GOODS_PIC":imagearr[0],@"GOODS_NAME":self.maindic[@"GOODS_NAME"],@"GOODS_ATTRIBUTE":self.guigeStr,@"GOODS_PRICE":self.guigePrice};
            addVC.seleSCarArray = @[orderdic];
            addVC.shopId = self.shangpingId;
            addVC.shopsxId = self.guigeId;
            addVC.shopNumId = shopnumstr;
            addVC.payType = @"立即购买";
            addVC.hidesBottomBarWhenPushed = YES;
            addVC.successBlock = ^{
                
            };
            
            NSString *strurl = [NSString stringWithFormat:@"/dashop/order/app/order_total.do?GOODS_ID=%@&ATTRIBUTE_DETAIL_ID=%@&GOODS_COUNT=%@&USER_ID=%@&COUPON_ID=",self.shangpingId,self.guigeId,shopnumstr,[UserDefault objectForKey:LogUserID]];
            NSString *endstr = [MethodClass returnUrlSetStrWSDLURL:strurl];
            [self querenOrderMethodWithUrl:endstr];
            
            [self.navigationController pushViewController:addVC animated:YES];
            
            
            weakself.backview.hidden = YES;
            [weakself.backview.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
            
        };
//        NSInteger numwidth = 0;
//        for (int i = 0; i < self.ggArray.count; i ++) {
//            NSDictionary *ggdic = self.ggArray[i];
//            NSString *constr = ggdic[@"ATTRIBUTE"];
//            CGSize size = [constr sizeWithFont:[UIFont systemFontOfSize:15*kJLXWidthScale] constrainedToSize: CGSizeMake(MAXFLOAT,35*kJLXWidthScale) lineBreakMode:NSLineBreakByWordWrapping];
//            numwidth = 20*kJLXWidthScale + size.width + numwidth;
//
//        }
//        UIScrollView *ggscview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 35*kJLXWidthScale)];
//        ggscview.contentSize = CGSizeMake(numwidth,35*kJLXWidthScale);
//        [shopview.ggbaview addSubview:ggscview];
        
        int num = 0;
        for (int i = 0; i < self.ggArray.count; i ++) {
            NSDictionary *ggdic = self.ggArray[i];
            NSString *constr = ggdic[@"ATTRIBUTE"];
            CGSize buttonsize = [constr sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18*kJLXWidthScale]}];
            MineButton *btn = [MineButton buttonWithType:UIButtonTypeCustom];
            [shopview.ggbaview addSubview:btn];
            btn.sd_layout
            .topSpaceToView(shopview.ggbaview, 8*kJLXWidthScale + (30*kJLXWidthScale + 5*kJLXWidthScale)*i)
            .leftSpaceToView(shopview.ggbaview, 8*kJLXWidthScale)
            .widthIs(buttonsize.width)
            .heightIs(30*kJLXWidthScale);
            //调节button大小
            btn.titleLabel.font = [UIFont systemFontOfSize:13*kJLXWidthScale];
            [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            btn.layer.masksToBounds = YES;
            btn.layer.cornerRadius = 8*kJLXWidthScale;
            btn.usinfo = ggdic;
            btn.tag = 370 + i;
            btn.backgroundColor = [UIColor lightGrayColor];
            num = btn.frame.origin.x + buttonsize.width ;
            [btn setTitle:constr forState:UIControlStateNormal];
            [btn addTarget:self action:@selector(ggButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            [self.butArray addObject:btn];
            if (i == 0) {
                btn.backgroundColor = [UIColor redColor];
                shopview.savelab.text = [NSString stringWithFormat:@"库存%@",ggdic[@"ATTRIBUTENUM"]];
                shopview.savelab.tag = 1001;
                shopview.pricelab.text = [NSString stringWithFormat:@"￥%.2f",[ggdic[@"ATTRIBUTEPRICE"] floatValue]];
                shopview.pricelab.tag = 1002;
                self.guigeId = ggdic[@"ATTRIBUTE_ID"];
                self.guigeStr = ggdic[@"ATTRIBUTE"];
                self.shangpingId = self.maindic[@"GOODS_ID"];
                self.guigePrice = ggdic[@"ATTRIBUTEPRICE"];
            }
        }
        [self.backview addSubview:shopview];
    }else{
        LoginController *loginVC = [[LoginController alloc]init];
        loginVC.logBlock = ^(NSDictionary *logdic) {
            
        };
        loginVC.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:loginVC animated:YES];
    }
   
}
//调到订单界面的方法
-(void)querenOrderMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
        
        [[NSOperationQueue mainQueue]addOperationWithBlock:^{
            
        }];
    } failBlock:^(NSError *error) {
        
    }];
}


-(void)ggButtonAction:(MineButton *)sender{
    UILabel *lab1 = [self.backview viewWithTag:1001];
    UILabel *lab2 = [self.backview viewWithTag:1002];
    for (int i = 0; i < self.butArray.count; i ++) {
        MyButton *btn = self.butArray[i];
        if (btn.tag == sender.tag) {
            btn.backgroundColor = [UIColor redColor];
            lab1.text = [NSString stringWithFormat:@"库存%@",sender.usinfo[@"ATTRIBUTENUM"]];
            lab2.text = [NSString stringWithFormat:@"￥%.2f",[sender.usinfo[@"ATTRIBUTEPRICE"] floatValue]];
            self.guigeId = sender.usinfo[@"ATTRIBUTE_ID"];
            self.guigeStr = sender.usinfo[@"ATTRIBUTE"];
            self.shangpingId = self.maindic[@"GOODS_ID"];
            self.guigePrice = sender.usinfo[@"ATTRIBUTEPRICE"];
        }else{
            btn.backgroundColor = [UIColor lightGrayColor];
        }
    }
    
    
    
}


-(void)GGXHshowShopDetailImageDataMethodWithUrl:(NSString *)url{
    
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
        self.ggArray = response;
        
    } failBlock:^(NSError *error) {
        
        
        
    }];
    
}
-(void)showShopDetailImageDataMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
        self.maindic = response;
        [[NSOperationQueue mainQueue]addOperationWithBlock:^{
            if ([self.maindic[@"ISNOCOLLECTION"] boolValue] == YES) {
                self.shoucanBtn.mineimagevi.image = [UIImage imageNamed:@"icon_collection_ed.png"];
                self.shoucanBtn.selected = YES;
            }
            NSString *imageurl = response[@"GOODS_PIC"];
            NSArray *imagearr = [imageurl componentsSeparatedByString:@","];
            NSMutableArray *imagesURLStrings = [NSMutableArray arrayWithCapacity:10];
            for (NSString *strurl in imagearr) {
                NSString *url = [MethodClass returnUrlSetStrWSDLURL:strurl];
                [imagesURLStrings addObject:url];
            }
                SDCycleScrollView *cycleScrollView3 = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, kScreenWidth, 350*kJLXWidthScale) delegate:self placeholderImage:[UIImage imageNamed:@"placeholder"]];
                cycleScrollView3.imageURLStringsGroup = imagesURLStrings;
                cycleScrollView3.autoScrollTimeInterval = 2.0;
                [self.headerview addSubview:cycleScrollView3];
            UILabel *titlab = [UILabel new];
            titlab.font = [UIFont systemFontOfSize:14*kJLXWidthScale];
            titlab.textAlignment = NSTextAlignmentLeft;
            titlab.textColor = [UIColor darkGrayColor];
            titlab.text = [NSString stringWithFormat:@"%@",response[@"GOODS_NAME"]];
            [self.headerview addSubview:titlab];
            titlab.sd_layout
            .topSpaceToView(cycleScrollView3, 10*kJLXWidthScale)
            .leftSpaceToView(self.headerview, 10*kJLXWidthScale)
            .rightSpaceToView(self.headerview, 10*kJLXWidthScale)
            .autoHeightRatio(0);
            
            UILabel *pricelab = [UILabel new];
            pricelab.font = [UIFont systemFontOfSize:16*kJLXWidthScale];
            pricelab.textAlignment = NSTextAlignmentLeft;
            pricelab.textColor = [UIColor redColor];
            pricelab.text = [NSString stringWithFormat:@"￥%@",response[@"GOODS_MINPRICE"]];
            [self.headerview addSubview:pricelab];
            pricelab.sd_layout
            .topSpaceToView(titlab, 5*kJLXWidthScale)
            .leftSpaceToView(self.headerview, 10*kJLXWidthScale)
            .widthIs(pricelab.text.length *12*kJLXWidthScale)
            .heightIs(35*kJLXWidthScale);
            UILabel *yjlab = [UILabel new];
            yjlab.font = [UIFont systemFontOfSize:13*kJLXWidthScale];
            yjlab.textAlignment = NSTextAlignmentLeft;
            yjlab.numberOfLines = 0;
            yjlab.textColor = [UIColor grayColor];
            NSString *oldPrice = [NSString stringWithFormat:@"%.2f",[response[@"GOODS_MARKETPRICE"]floatValue]];
            //获取字符串的长度
            NSUInteger length = [oldPrice length];
            //从这里开始就是设置富文本的属性
            NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:oldPrice];
            //设置格式下划线还是删除线
            [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle)  range:NSMakeRange(0, length)];
            //设置线条颜色
            [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor grayColor] range:NSMakeRange(0, length)];
            //添加线条
            [yjlab setAttributedText:attri];
            [self.headerview addSubview:yjlab];
            yjlab.sd_layout
            .topSpaceToView(titlab, 5*kJLXWidthScale)
            .leftSpaceToView(pricelab, 10*kJLXWidthScale)
            .heightIs(35*kJLXWidthScale)
            .widthIs(yjlab.text.length *10);
            
            
            MineButton *btn = [MineButton buttonWithType:UIButtonTypeCustom];
            [btn addTarget:self action:@selector(pinglunShopButtonAction:) forControlEvents:UIControlEventTouchUpInside];
            [self.headerview addSubview:btn];
            btn.sd_layout
            .centerYEqualToView(pricelab)
            .widthIs(70*kJLXWidthScale)
            .heightIs(30*kJLXWidthScale)
            .rightSpaceToView(self.headerview, 10*kJLXWidthScale);
            btn.mineimagevi = [UIImageView new];
            btn.mineimagevi.userInteractionEnabled = NO;
            [btn addSubview:btn.mineimagevi];
            btn.mineimagevi.sd_layout
            .topSpaceToView(btn, 0)
            .bottomSpaceToView(btn, 0)
            .leftSpaceToView(btn, 0)
            .widthIs(30*kJLXWidthScale);
            
            btn.minlab = [UILabel new];
            btn.minlab.font = [UIFont systemFontOfSize:15*kJLXWidthScale];
            btn.minlab.userInteractionEnabled = NO;
            [btn addSubview:btn.minlab];
            btn.minlab.sd_layout
            .topSpaceToView(btn, 0)
            .bottomSpaceToView(btn, 0)
            .rightSpaceToView(btn, 0)
            .widthIs(35*kJLXWidthScale);
            
            btn.minlab.text = @"评论";
            btn.minlab.textColor = [UIColor lightGrayColor];
            btn.mineimagevi.image = [UIImage imageNamed:@"chat_icon.png"];
            
            
            UILabel *detaillab = [UILabel new];
            detaillab.text = @"详情";
            detaillab.layer.masksToBounds = YES;
            detaillab.layer.borderColor = [UIColor orangeColor].CGColor;
            detaillab.layer.borderWidth = 0.8;
            detaillab.textColor = [[UIColor orangeColor] colorWithAlphaComponent:0.7];
            detaillab.textAlignment = NSTextAlignmentCenter;
            [self.headerview addSubview:detaillab];
            detaillab.sd_layout
            .bottomSpaceToView(self.headerview, 0)
            .leftSpaceToView(self.headerview, 0)
            .rightSpaceToView(self.headerview, 0)
            .heightIs(40*kJLXWidthScale);
            
            UIView *linevie = [UIView new];
            linevie.backgroundColor = LineBackColor;
            [self.headerview addSubview:linevie];
            linevie.sd_layout
            .bottomSpaceToView(detaillab, 0)
            .leftSpaceToView(self.headerview, 0)
            .rightSpaceToView(self.headerview, 0)
            .heightIs(10*kJLXWidthScale);
            NSString *footimageurl = response[@"GOODS_DETAILSPIC"];
            NSArray *footimagearr = [footimageurl componentsSeparatedByString:@","];
           self.footHeight = 0;
            UIView *footview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, self.footHeight)];
            NSMutableArray *muArray = [NSMutableArray arrayWithCapacity:10];
            for (int i = 0; i < footimagearr.count; i ++) {
                NSString *url = [MethodClass returnUrlSetStrWSDLURL:footimagearr[i]];
                NSURL *uURL = [NSURL URLWithString:url];
                UIImageView *footimagevi = [[UIImageView alloc]init];
                [footimagevi sd_setImageWithURL:uURL completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
                    if (image.size.width > kScreenWidth) {
                        footimagevi.frame = CGRectMake(0, 0, kScreenWidth, image.size.height*kScreenWidth/image.size.width);
                    }else{
                        footimagevi.frame = CGRectMake(0, 0, image.size.width,image.size.height);
                    }
                    footview.frame = CGRectMake(0, 0, kScreenWidth, footview.size.height + footimagevi.size.height);
                    footimagevi.frame = CGRectMake(0, self.footHeight, kScreenWidth,footimagevi.size.height);
                    [footview addSubview:footimagevi];
                    [muArray addObject:footimagevi];
                    if (i == footimagearr.count - 1) {
                        self.imgeArray = [muArray copy];
                        [self.listTableview reloadData];
                    }
                   self.footHeight = self.footHeight + footimagevi.size.height;
                }];
            }
        }];
    } failBlock:^(NSError *error) {
       
        
        
    }];
    
}


-(void)pinglunShopButtonAction:(MineButton *)sender{
    MorePingLunController *mrvc = [[MorePingLunController alloc]init];
    mrvc.navigationItem.title = @"商品评论";
    mrvc.condic = self.usdic;
    NSString *strurl = [NSString stringWithFormat:@"/dashop/goodsrate/app/list.do?GOODS_ID=%@&CurrentPage=1",self.usdic[@"GOODS_ID"]];
    mrvc.urlstr = strurl;
    [self.navigationController pushViewController:mrvc animated:YES];
}

-(void)showShopDetailNumberDataMethodWithUrl:(NSString *)url{
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
        
        [[NSOperationQueue mainQueue]addOperationWithBlock:^{
            
            
        }];
    } failBlock:^(NSError *error) {
        
    }];
    
}

-(void)createTableviewMethod{
    self.listTableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - 100*kJLXWidthScale) style:UITableViewStylePlain];
    [self.view addSubview:self.listTableview];
    if (kScreenHeight == 812) {
        self.listTableview.sd_layout
        .bottomSpaceToView(self.view, 34);
    }
    self.listTableview.dataSource = self;
    self.listTableview.delegate = self;
    //分隔线
    self.listTableview.separatorStyle = UITableViewCellAccessoryNone;
    //去掉尾部多余的空白
    [self.listTableview setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
    [self.listTableview registerClass:[UITableViewCell class] forCellReuseIdentifier:@"onecell"];
    self.headerview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 500*kJLXWidthScale)];
    self.headerview.backgroundColor = [UIColor whiteColor];
    self.listTableview.tableHeaderView = self.headerview;
    
    
}
//添加购物车
-(void)addShopingCarRequestMethodWithUrl:(NSString *)url{
    
    [YQNetworking getWithUrl:url refreshRequest:YES cache:NO params:nil progressBlock:^(int64_t bytesRead, int64_t totalBytes) {
    } successBlock:^(id response) {
        
        KMLog(@"添加购物车成功");
    } failBlock:^(NSError *error) {
        
        
        
    }];
    
}

#pragma mark - SDCycleScrollViewDelegate

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index
{
    NSLog(@"---点击了第%ld张图片", (long)index);
  
    //    [self.navigationController pushViewController:[NSClassFromString(@"DemoVCWithXib") new] animated:YES];
}

#pragma mark --UITableViewDelegate,UITableViewDataSource--


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"onecell" forIndexPath:indexPath];
    NSInteger numheight = 0;
    for (int i = 0; i < self.imgeArray.count; i ++) {
        UIImageView *imaagevi = self.imgeArray[i];
        imaagevi.frame = CGRectMake(0, numheight,kScreenWidth, imaagevi.size.height);
        numheight = numheight + imaagevi.size.height;
        [cell.contentView addSubview:imaagevi];
    }
    return cell;
    
}



-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger numheight = 0;
    for (int i = 0; i < _imgeArray.count; i ++) {
        UIImageView *imvi = _imgeArray[i];
        numheight = numheight + imvi.size.height;
    }
    return numheight;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
}

//封装提示框方法
-(void)alerWithMessage:(NSString *)msg{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
    [self presentViewController:alert animated:YES completion:^{
        //延迟1秒自动消失
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [alert dismissViewControllerAnimated:YES completion:nil];
        });
    }];
}

@end
